// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   WayUtil.java

package team.common.utility;

import java.util.ArrayList;
import java.util.StringTokenizer;

public class WayUtil
{

    public WayUtil()
    {
    }

    public static String fillBlank(String s, int max)
    {
        int s_len = s.length();
        for(int i = s_len; i < max; i++)
            s = (new StringBuilder(String.valueOf(s))).append(" ").toString();

        return s;
    }

    public static long parseLong(String s)
    {
        if(s == null || s.equals(""))
            return -1L;
        try
        {
            return Long.parseLong(s);
        }
        catch(Exception e)
        {
            return -1L;
        }
    }

    public static int parseInt(String s)
    {
        if(s == null || s.equals(""))
            return -1;
        try
        {
            return Integer.parseInt(s);
        }
        catch(Exception e)
        {
            return -1;
        }
    }

    public static float parseFloat(String s)
    {
        if(s == null || s.equals(""))
            return -1F;
        try
        {
            return Float.parseFloat(s);
        }
        catch(Exception e)
        {
            return -1F;
        }
    }

    public static double parseDouble(String s)
    {
        if(s == null || s.equals(""))
            return -1D;
        try
        {
            return Double.parseDouble(s);
        }
        catch(Exception e)
        {
            return -1D;
        }
    }

    public static String replace(String src, String oldstr, String newstr)
    {
        if(src == null)
            return null;
        StringBuffer dest = new StringBuffer("");
        int len = oldstr.length();
        int srclen = src.length();
        int pos = 0;
        int oldpos;
        for(oldpos = 0; (pos = src.indexOf(oldstr, oldpos)) >= 0; oldpos = pos + len)
        {
            dest.append(src.substring(oldpos, pos));
            dest.append(newstr);
        }

        if(oldpos < srclen)
            dest.append(src.substring(oldpos, srclen));
        return dest.toString();
    }

    public static String[] split(String strVal, String divider, int arrayLength)
    {
        String rtnArray[] = new String[arrayLength];
        strVal = replace(strVal, (new StringBuilder(String.valueOf(divider))).append(divider).toString(), (new StringBuilder(String.valueOf(divider))).append(" ").append(divider).toString());
        strVal = replace(strVal, (new StringBuilder(String.valueOf(divider))).append(divider).toString(), (new StringBuilder(String.valueOf(divider))).append(" ").append(divider).toString());
        strVal = replace(strVal, (new StringBuilder(String.valueOf(divider))).append(divider).toString(), (new StringBuilder(String.valueOf(divider))).append(" ").append(divider).toString());
        strVal = replace(strVal, (new StringBuilder(String.valueOf(divider))).append(divider).toString(), (new StringBuilder(String.valueOf(divider))).append(" ").append(divider).toString());
        strVal = replace(strVal, (new StringBuilder(String.valueOf(divider))).append(divider).toString(), (new StringBuilder(String.valueOf(divider))).append(" ").append(divider).toString());
        strVal = replace(strVal, (new StringBuilder(String.valueOf(divider))).append(divider).toString(), (new StringBuilder(String.valueOf(divider))).append(" ").append(divider).toString());
        strVal = replace(strVal, (new StringBuilder(String.valueOf(divider))).append(divider).toString(), (new StringBuilder(String.valueOf(divider))).append(" ").append(divider).toString());
        if(strVal.startsWith(divider))
            strVal = (new StringBuilder(":")).append(strVal).toString();
        else
            strVal = (new StringBuilder(":")).append(divider).append(strVal).toString();
        StringTokenizer st = new StringTokenizer(strVal, divider);
        int nIndex = 0;
        while(st.hasMoreTokens()) 
            if(nIndex == 0)
            {
                st.nextToken();
                nIndex++;
            } else
            {
                rtnArray[nIndex - 1] = st.nextToken();
                nIndex++;
            }
        return rtnArray;
    }

    public static String[] split(String strVal, String divider)
    {
        StringTokenizer st = new StringTokenizer(strVal, divider);
        ArrayList al = new ArrayList();
        int nIndex;
        for(nIndex = 0; st.hasMoreTokens(); nIndex++)
            al.add(nIndex, st.nextToken());

        String rtnArray[] = new String[nIndex];
        for(int i = 0; i < al.size(); i++)
            rtnArray[i] = al.get(i).toString();

        return rtnArray;
    }

    public static String reverseTrim(String pattern, String oriString, String c, String direction)
    {
        return reverseTrim(pattern.length(), oriString, c, direction);
    }

    public static String reverseTrim(int nStrLen, String oriString, String c, String direction)
    {
        StringBuffer strRtn = new StringBuffer();
        int nOri = oriString.length();
        int nDiff = nStrLen - nOri;
        if(nStrLen > nOri && direction.toUpperCase().equals("L"))
        {
            for(int i = 0; i < nDiff; i++)
                strRtn.append(c);

        }
        strRtn.append(oriString);
        if(nStrLen > nOri && direction.toUpperCase().equals("R"))
        {
            for(int i = 0; i < nDiff; i++)
                strRtn.append(c);

        }
        return strRtn.toString();
    }

    public static String parseSpecialChar(String str)
    {
        str = replace(str, "\b", "\\b");
        str = replace(str, "\t", "\\t");
        str = replace(str, "\n", "\\n");
        str = replace(str, "\f", "\\f");
        str = replace(str, "\r", "\\r");
        return str;
    }
}
